package cn.wolfcode.luowowo.query;

import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Pageable;
import org.springframework.util.StringUtils;

@Setter
@Getter
public class QueryObject {
    private Integer currentPage = 1;
    private Integer pageSize = 5;
    private String keyword;
    //设置分页对象
    private Pageable pageable;
    public Pageable getPageable(){
        if(pageable == null){
            return PageRequest.of(currentPage-1,pageSize, Sort.Direction.ASC,"_id");
        }
        return pageable;
    }
    public String getKeyword(){
        return StringUtils.hasLength(keyword)? keyword : null;
    }
}
